#ifndef PICDIALOG_H
#define PICDIALOG_H

#include <QDialog>
#include <QFileDialog>
#include "DealH/fileIO.h"
#include "DealH/Common.h"
class sandLight;
void delayTime(int k);
namespace Ui {
class picDialog;
}
class picDialog : public QDialog
{
    Q_OBJECT

public:
    explicit picDialog(QWidget *parent = nullptr);
    picDialog(const reflect& N,sandLight *SdNew,QWidget *parent = nullptr);
    ~picDialog();
    void load_Pic();
    void clear_Pic();
    dealBMP* Re_picInfo();  //返回图片信息
    bool reflectWay(long& siteW,long& siteH,reflect picCount,double& c,rflRange* range);
    template <typename T>
    static void ctrlPicBtn(const reflect& N,int& cnt,picDialog** pD,QString& str,long suitPicw,long suitPich,T* t){
        cnt++;
        delayTime(10);
        if(cnt==1){
            if(pD[N]==nullptr){
                pD[N]=new picDialog(N,t);
                pD[N]->setSuitHW(suitPicw,suitPich);
                pD[N]->setModal(true);
                pD[N]->show();
                pD[N]->setWindowTitle(str);
            }
            else{
                pD[N]->show();
                pD[N]->setSuitHW(suitPicw,suitPich);
                if(pD[N]->Re_picInfo()!=nullptr){
                    pD[N]->load_Pic();
                }
            }
            cnt=0;
        }
        else if(cnt>=2){
            if(pD!=nullptr){
                pD[N]->clear_Pic();
            }
            cnt=0;
        }
    }
    void closeEvent(QCloseEvent *event);
    void setSuitHW(long& picW,long& picH);
private slots:
    void on_load_Btn_clicked(); //加载图片
    void on_clearload_Btn_clicked(); //清除图片并析构图片
    void on_saveload_Btn_clicked();

private:
    //QPushButton* m_Btn;
    sandLight *m_SdNew=nullptr;
    reflect m_N;
    long m_suitPicW=0;
    long m_suitPicH=0;//适配的图片长宽信息，提醒用户
public:
    Ui::picDialog *ui;
    dealBMP* Pic=nullptr;
    QImage* image=nullptr;
    uchar* ptr;
};
#endif // PICDIALOG_H
